﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class Member
    {
        public string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source='C:\\Database\\DB_DsTruong.dat'";


        private String user;
        public String User
        {
            get { return user; }
            set { user = value; }
        }

        private String password;
        public String Password
        {
            get { return password; }
            set { password = value; }
        }

        private String schoolName;
        public String SchoolName
        {
            get { return schoolName; }
            set { schoolName = value; }
        }

        public Member()
        {
        }


        public String getPasswordByUser(String user_name)
        {
            Member m = new Member();
            OleDbConnection conn = new OleDbConnection(connstr);
            conn.Open();
            string query = "SELECT MatKhau From [Member$] where TaiKhoan = '"+user_name+"'";
            try
            {
                OleDbCommand cmd = new OleDbCommand(query, conn);
                m.Password = cmd.ExecuteScalar().ToString();
                return m.Password;
                conn.Close();
                
            }
            catch (Exception e)
            {
                conn.Close();
                return "specialErrorzxcvbnm";
            }
        }
        public String getSchoolsNameByUser(String user_name)
        {
            Member m = new Member();
            OleDbConnection conn = new OleDbConnection(connstr);
            conn.Open();
            string query = "SELECT TruongTHCS From [Member$] where TaiKhoan = '" + user_name + "'";
            try
            {
                OleDbCommand cmd = new OleDbCommand(query, conn);
                m.SchoolName = cmd.ExecuteScalar().ToString();
                return m.SchoolName;
                conn.Close();

            }
            catch (Exception e)
            {
                conn.Close();
                return "specialErrorzxcvbnm";
            }
        }
        public void editPassByUser(String user_, String matkhau)
        {
                OleDbConnection conn = new OleDbConnection(connstr);
                conn.Open();
                String query = "UPDATE [Member$] SET MatKhau = @matkhau Where TaiKhoan = '" + user_ + "'";
                OleDbCommand cmd = new OleDbCommand(query, conn);
                cmd.Parameters.AddWithValue("@matkhau", SqlDbType.VarChar);
                cmd.Parameters["@matkhau"].Value = matkhau;
                cmd.ExecuteNonQuery();
                conn.Close();
            
        }
    }
}
